//
//  ChapterContent.m
//  ebook
//
//  Created by 吴超飞 on 16/3/1.
//  Copyright © 2016年 Moton. All rights reserved.
//

#import "ChapterContent.h"

@implementation ChapterContent

- (id)initWithDict:(NSDictionary *)aDict{

    self = [super init];
    if (self) {
        self.bookid = aDict[@"bookid"];
        self.chaptercontent = aDict[@"chaptercontent"];
        self.chapterid = aDict[@"chapterid"];
        self.chaptername = aDict[@"chaptername"];
        self.sourceurl = aDict[@"sourceurl"];
    }
    return self;
}

- (id)copyWithZone:(NSZone *)zone {
    
    ChapterContent *copyInstance = [[[self class] allocWithZone:zone] init];
    copyInstance.bookid = [self.bookid copyWithZone:zone];
    copyInstance.chaptercontent = [self.chaptercontent copyWithZone:zone];
    copyInstance.chapterid = [self.chapterid copyWithZone:zone];
    copyInstance.chaptername = [self.chaptername copyWithZone:zone];
    copyInstance.sourceurl = [self.sourceurl copyWithZone:zone];
    return copyInstance;
}

-(NSString *)chaptercontent{
    
    return [self filterHTML:_chaptercontent];
}

- (NSString *)filterHTML:(NSString *)html {
    
    html = [html stringByReplacingOccurrencesOfString:@"<br />" withString:@"\n"];
    html = [html stringByReplacingOccurrencesOfString:@"<br/>" withString:@"\n"];
    html = [html stringByReplacingOccurrencesOfString:@"<br>" withString:@"\n"];
    html = [html stringByReplacingOccurrencesOfString:@"</br>" withString:@"\n"];
    html = [html stringByReplacingOccurrencesOfString:@"\r" withString:@"\n"];
    html = [html stringByReplacingOccurrencesOfString:@"\n+"
                                             withString:@"\n" options:NSRegularExpressionSearch
                                                  range:NSMakeRange (0, html.length)];
    
    html = [html stringByReplacingOccurrencesOfString:@"　" withString:@"\0"];//   中文全角空格（\u3000） 转换成 空字符（\0）
    html = [html stringByReplacingOccurrencesOfString:@"\t" withString:@""];

    return html;
}

@end
